N = 6;
step = .001;
[templateX template] = template1(step);
signal = [zeros(1, length(template)) template zeros(1, length(template)) -template zeros(1, length(template)) template zeros(1, length(template))];
signalX = 1:length(signal);
generatedFunctions = integerPowers(N);

distributedSignal = Composite();
partLength = round(length(signal) / 3);
start1 = 1;
end1 = partLength;
start2 = partLength + 1;
end2 = 2*partLength;
start3 = 2*partLength + 1;
end3 = length(signal);
distributedSignal{1} = signal(start1:end1);
distributedSignal{2} = signal(start2:end2);
distributedSignal{3} = signal(start3:end3);

%%
tic;
[PTotal, ~, eTotal]=KunchenkoMatrix(signal, template, step, generatedFunctions);
singleTime = toc;
display(strcat('Elapsed time in single mode: ', num2str(singleTime)));

tic;
spmd
    [P, ~, e]=KunchenkoMatrix(distributedSignal, template, step, generatedFunctions);
end;
parallelTime = toc;
display(strcat('Elapsed time in parallel mode: ', num2str(parallelTime)));
%%
scaledE1 = KunchenkoEffectogramScaling(signalX(start1:end1), e{1}, templateX);
scaledE2 = KunchenkoEffectogramScaling(signalX(start2:end2), e{2}, templateX);
scaledE3 = KunchenkoEffectogramScaling(signalX(start3:end3), e{3}, templateX);
scaledAllE = [scaledE1 scaledE2 scaledE3];
% output results
figure('Color','white');
subplot(3,1,1);
plot(signalX, signal);
grid on;
subplot(3,1,2);
plot(signalX, [distributedSignal{1} distributedSignal{2} distributedSignal{3}]);
grid on;
subplot(3,1,3);
plot(signalX, scaledAllE);
grid on;